# -*- coding: utf-8 -*-

import os
import re
path = r"D:\质检\左中\国家库\150000内蒙古自治区土地利用总体规划调整完善数据库成果汇交"

all = os.walk(path)
for dir,f,file in all:
    for each in file:
        src  = dir+os.sep+each
        a = re.match(r"[0-9]{9}",each)
        if a:
            c = re.findall(r"[0-9]{3}",dir)
            os.rename(src,dir+os.sep+"150521"+c[6]+each[9:])
        b = re.match(r"[0-6]{6}\D+",each)
        if b:
            os.rename(src,dir+os.sep+"150521"+each[6:])